﻿package com.zkingsoft.actions.admin.pc;

import java.util.Arrays;

import javax.annotation.Resource;

import com.zkingsoft.services.pc.PcFoodCategoryService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.pc.PcFoodCategory;
import com.zkingsoft.model.sys.SysFunction;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.util.WebUtil;
import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.pojo.AjaxResult;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zkingsoft.anotations.RemoveRequestToken;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2017-03-14 14:37
 */
@Controller
@RequestMapping(value = "admin/pcFoodCategory")
public class PcFoodCategoryController extends BaseController{

	@Resource
	private PcFoodCategoryService pcFoodCategoryService;
	
	@Resource
	private MatrixAdapter matrixAdapter;
	
	
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="PcFoodCategory_BEV";
	
	public static final String fnCode = "PcFoodCategory";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(PcFoodCategory pcFoodCategory, PaginationVO pageVo) {
		matrixAdapter.isBtnPermitted(search);
		return showList(pcFoodCategoryService, pcFoodCategory, pageVo);
	}
   	
	/**
	 * 新增或者修改页面
	 */   
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(PcFoodCategory pcFoodCategory) {
		if (pcFoodCategory.getFooId() != null) {
	   		matrixAdapter.isBtnPermitted(edit);
	   		pcFoodCategory.setFooId(((PcFoodCategory)WebUtil.getSessionAttribute(BEV)).getFooId());
	   		AjaxResult result=modify(pcFoodCategoryService, WebUtil.getSessionAttribute(BEV), pcFoodCategory, "原材料分类");
	   	// 因为页面是一直打开的需要存新的值
	   		WebUtil.setSessionAttribute(BEV,pcFoodCategory);
			return  result;
		} else {
			matrixAdapter.isBtnPermitted(add);
			return add(pcFoodCategoryService, pcFoodCategory, "原材料分类");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		matrixAdapter.isBtnPermitted(edit);
		PcFoodCategory pcFoodCategory;
		if (id != null) {
			pcFoodCategory = pcFoodCategoryService.findById(id);
			WebUtil.getRequest().setAttribute("obj", pcFoodCategory);
			WebUtil.setSessionAttribute(BEV, pcFoodCategory);
		}
		return "admin/pc/PcFoodCategory-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		matrixAdapter.isBtnPermitted(del);
		return remove(pcFoodCategoryService, keys);
	}
 	/**
	 * 显示所有功能
	 */
 	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all() {
		return findByModel(pcFoodCategoryService, null);
	}
 	
	/**
	 * id查询
	 * @param pcFoodCategory
	 */
	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(PcFoodCategory pcFoodCategory) {
		pcFoodCategory=pcFoodCategoryService.findById(pcFoodCategory.getFooId());
		WebUtil.setSessionAttribute(BEV, pcFoodCategory);
		return new AjaxResult(AjaxResult.STATUS_OK, Arrays.asList(pcFoodCategory));
	}
}